# Author : Fengyuan(Franklin) Zhang
# Date : 2019/1/4
# Description : Test for service SDK
from __init__ import OGMSService_DEBUG


server = OGMSService_DEBUG.CreateServer("127.0.0.1", 8060)
# server = OGMSService_DEBUG.CreateServer("172.21.212.7", 8060)
server.connect()
if server.connect() : 
    access = server.createServiceAccess()
    list_ms = access.getModelServicesList()
    for index, item in enumerate(list_ms):
        print "ID : " + item.id + " - Name : " + item.name + " - Type : " + item.type 
    dataid = access.uploadDataByFile("aread8_input", "E:\\DemoData\\GeoModeling\\udx_zip_d8\\d8.tif")
    print "AreaD8 - Input Data ID : " + dataid
    swat = access.getModelServiceByID("5acf6bde18f9e109f0aafa38")
    recordid = swat.invoke([access.createDataConfigurationItem("RUNSTATE", "D8FlowDirection", dataid)])
    record = access.getModelServiceRunningRecordByID(recordid)
    instance = access.getModelServiceInstanceByGUID(record.guid)
    instance.wait4Status(4, 7200, True)
    print "AreaD8 has been finished"
    record.refresh()
    for index,item in enumerate(record.outputs):
        dat = access.getDataByID(item.dataid)
        dat.save("E:\\DemoData\\GeoModeling\\udx_zip_d8\\AreaD8_" + item.eventname + ".zip")